//定义保存cookie的函数(设置cookie的key直接value和过期时间,其中时间参数可以不填写)   wangruiyong

function setCookie(name,value,days){

//处理时间 shijian

var nowDate = new Date();

nowDate.setDate(nowDate.getDate() + days);

//直接保存

if(days == undefined){

document.cookie = name + "=" + value;

}else{

document.cookie = name + "=" + value + ";expires=" + nowDate.toUTCString();

}

}

//取出cookie的函数(传入的参数为cookie的key值,取出响应的value值)

function getCookie(name){

var res = document.cookie;

var array = res.split("; ");

for(var i = 0;i < array.length;i++){

var item = array[i].split("=");

if(item[0] == name){

return item[1];

}

}

}

//删除cookie的函数(利用key值删除cookie)

function removeCookie(name){

setCookie(name,"",-1);

}